<template>
  <div>
    <div class="wrapper">
      <div class="container">
        <div class="order-wrap">
          <div class="item-order">
            <div class="icon-succ"></div>
            <div class="order-info">
              <h2>订单提交成功！去付款咯～</h2>
              <p>请在
                <span>30分</span>
                内完成支付, 超时后将取消订单
              </p>
              <p>收货信息：Admin 183****0972 北京 北京市 朝阳区 望京街道 望京(地铁站)</p>
            </div>
            <div class="order-total">
              <p>应付总额：
                <span>{{list.payment}}</span>
                元
              </p>
              <p>订单详情
                <em class="icon-down up" :class="{checked: showDetail}" @click="showDetail=!showDetail"></em>
              </p>
            </div>
          </div>
          <div class="item-detail" v-if="showDetail">
            <div class="item">
              <div class="detail-title">订单号：</div>
              <div class="detail-info theme-color">{{list.orderNo}}</div>
            </div>
            <div class="item">
              <div class="detail-title">收货信息：</div>
              <div class="detail-info">{{userInfo}}</div>
            </div>
            <div class="item good">
              <div class="detail-title">商品名称：</div>
              <div class="detail-info">
                <ul>
                  <li v-for="(item,index) in orderDetail" :key="index">
                    <img v-lazy="item.productImage"/>
                    {{item.productName}}
                  </li>
                </ul>
              </div>
            </div>
            <div class="item">
              <div class="detail-title">发票信息：</div>
              <div class="detail-info">电子发票 个人</div>
            </div>
          </div>
        </div>
        <div class="item-pay">
          <h3>选择以下支付方式付款</h3>
          <div class="pay-way">
            <p>支付平台</p>
            <div class="pay pay-ali" :class="{'checked': PayWay === 1}" @click="submitPay(1)"></div>
            <div class="pay pay-wechat" :class="{'checked': PayWay === 2}" @click="submitPay(2)"></div>
          </div>
        </div>
      </div>
    </div>
    <div class="wxModel" v-show="showWxModel">
      <div class="icon">
        <i @click="showWxModel=false" class="el-icon-close"></i>
      </div>
      <img :src="wxPay" alt="">
    </div>
  </div>
</template>

<script>
import {getOrderDetail, wxPay} from "../api/home";

export default {
  name: 'orderPay',
  data () {
    return {
      orderId: this.$route.query.orderNo,
      showDetail: true,
      list: {},
      orderDetail: [],
      addressInfo: {},
      PayWay: 0,
      wxPay: '',
      showWxModel: false
    }
  },
  methods: {
    getOrder () {
      getOrderDetail(this.orderId).then(res => {
        const data = res.data.data
        this.list = data
        this.orderDetail = data.orderItemVoList
        this.addressInfo = data.shippingVo
      })
    },
    submitPay (payType) {
      if (payType === 1) {
        this.PayWay = 1
        // 支付宝支付
        window.open('/#/order/aliPay?orderId=' + this.orderId, '_blank')
      } else {
        //  微信支付
        wxPay({
          orderId: this.orderId,
          orderName: 'Jing',
          amount: 0.01,
          payType: 2
        }).then(res => {
          console.log(res)
          this.showWxModel = true
          const data = res.data.data
          this.QRCode.toDataURL(data.content).then(imgUrl => {
            this.wxPay = imgUrl
          })
        })
      }
    }
  },
  mounted () {
    console.log(1)
    this.getOrder()
  },
  computed: {
    userInfo () {
      return `${this.addressInfo.receiverName} ${this.addressInfo.receiverMobile} ${this.addressInfo.receiverProvince} ${this.addressInfo.receiverCity} ${this.addressInfo.receiverDistrict}`
    }
  }
}
</script>

<style lang="scss" scoped>
.wrapper {
  background-color: #f5f5f5;
  padding-top: 30px;
  padding-bottom: 61px;

  .order-wrap {
    padding: 62px 50px;
    background-color: #ffffff;
    font-size: 14px;
    margin-bottom: 30px;

    .item-order {
      display: flex;
      align-items: center;

      .icon-succ {
        width: 90px;
        height: 90px;
        border-radius: 50%;
        background: url('/imgs/icon-gou.png') #80c58a no-repeat center;
        background-size: 60px;
        margin-right: 40px;
      }

      .order-info {
        margin-right: 248px;

        h2 {
          font-size: 24px;
          color: #333333;
          margin-bottom: 20px;
        }

        p {
          color: #666666;

          span {
            color: #ff6700;
          }
        }
      }

      .order-total {
        & > p:first-child {
          margin-bottom: 30px;
        }

        span {
          font-size: 28px;
          color: #ff6700;
        }

        .icon-down {
          display: inline-block;
          width: 14px;
          height: 10px;
          background: url('/imgs/icon-down.png') no-repeat center;
          background-size: contain;
          margin-left: 9px;
          transition: all .5s;
          cursor: pointer;

          &.up {
            transform: rotate(180deg);
          }
        }

        .icon-up {
          transform: rotate(180deg);
        }
      }
    }

    .item-detail {
      border-top: 1px solid #d7d7d7;
      padding-top: 47px;
      padding-left: 130px;
      font-size: 14px;
      margin-top: 45px;

      .item {
        margin-bottom: 19px;

        .detail-title {
          float: left;
          width: 100px;
        }

        .detail-info {
          display: inline-block;

          img {
            width: 30px;
            vertical-align: middle;
          }
        }
      }
    }
  }

  .item-pay {
    padding: 26px 50px 72px;
    background-color: #ffffff;
    color: #333333;

    h3 {
      font-size: 20px;
      font-weight: 200;
      color: #333333;
      padding-bottom: 24px;
      border-bottom: 1px solid #d7d7d7;
      margin-bottom: 26px;
    }

    .pay-way {
      font-size: 18px;

      .pay {
        display: inline-block;
        width: 188px;
        height: 64px;
        border: 1px solid #d7d7d7;
        cursor: pointer;

        &:last-child {
          margin-left: 20px;
        }

        &.checked {
          border: 1px solid #ff6700;
        }
      }

      .pay-ali {
        background: url('/imgs/pay/icon-ali.png') no-repeat center;
        background-size: 103px 38px;
        margin-top: 19px;
      }

      .pay-wechat {
        background: url('/imgs/pay/icon-wechat.png') no-repeat center;
        background-size: 103px 38px;
      }
    }
  }
}

.wxModel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 300px;
  height: 300px;
  /*background: #8492a6;*/
  z-index: 5;

  .icon {
    text-align: right;
    height: 20px;

    i {
      font-size: 20px;
      cursor: pointer;
      transition: .2s linear;

      &:hover {
        font-size: 24px;
      }
    }
  }

  img {
    width: 100%;
    line-height: 300px;
  }
}
</style>
